package com.zxdemo.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zxdemo.mybatis.dao.UserRoleMapper;
import com.zxdemo.service.UserRoleService;

@Service("userRoleService")
public class UserRoleServiceImpl implements UserRoleService{
	@Autowired
	private UserRoleMapper userRoleMapper;
	@Override
	public List<Long> queryRoleIdList(Long userId) {
		// TODO Auto-generated method stub
		return userRoleMapper.queryRoleIdList(userId);
	}

	@Override
	public int delete(Long userId) {
		// TODO Auto-generated method stub
		return userRoleMapper.delete(userId);
	}

	@Override
	@Transactional
	public void saveOrUpdate(Long userId, List<Long> roleIdList) {
		// TODO Auto-generated method stub
		if(roleIdList.size()==0)
		{
			return ;
		}
		//先删除用户角色关系
		userRoleMapper.delete(userId);
		//更新用户角色关系
		userRoleMapper.save(userId, roleIdList);
		
	}

}
